import Taro from "@tarojs/taro";
import React, { useEffect, useState } from "react";
import { View, Text } from "@tarojs/components";

import "./index.module.scss";
import { AtCalendar } from "taro-ui";
import { useDispatch, useSelector } from "react-redux";

import { MIN_DATE, MAX_DATE } from "@/common/constant";
import { RootState } from "@/store";

const Index = () => {
  const { dptDate } = useSelector((state: RootState) => state.flightIndex);
  // console.log(dptDate);

  const dispatch = useDispatch();

  const onDateSelect = (date: any) => {
    console.log(date);

    const {
      value: { start },
    } = date;
    dispatch({
      type: "flightIndex/updateState",
      payload: {
        dptDate: start,
      },
    });
    Taro.navigateBack();
  };
  useEffect(() => {}, []);

  return (
    <View className="calendar-page">
      <AtCalendar
        currentDate={dptDate}
        minDate={MIN_DATE}
        maxDate={MAX_DATE}
        onSelectDate={onDateSelect}
      ></AtCalendar>
    </View>
  );
};

export default Index;
